<?php

// $Id$
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
/**
 * Function used to display an horizontal menu inside the admin panel
 *
 * Enable webmasters to navigate thru the module's features.
 * Each time you select an option in the admin panel of the news module, this option is highlighted in this menu
 *
 * @package News
 * @author - stolen to the Newbb team ;-)
 * @copyright	(c) The Xoops Project - www.xoops.org
*/

include '../xoops_version.php';

function adminmenu($currentoption = 0, $breadcrumb = '')
{
global $modversion, $adminmenu, $xoopsDB, $xoopsConfig, $xoopsModule;
$myts =& MyTextSanitizer::getInstance();
	
	/* Nice buttons styles */
	echo "
    	<style type='text/css'>
    	#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 0px solid black; border-right: 0px solid black; margin: 0; }
    	#buttonbar { float:left; width:100%; background: #e7e7e7 url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/bg.png') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 0px solid black; border-right: 0px solid black; margin-bottom: 0px; }
    	#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }
		#buttonbar li { display:inline; margin:0; padding:0; }
		#buttonbar a { float:left; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }
		#buttonbar a span { float:left; display:block; background:url('" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/right_both.png') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }
		/* Commented Backslash Hack hides rule from IE5-Mac \*/
		#buttonbar a span {float:none;}
		/* End IE5-Mac hack */
		#buttonbar a:hover span { color:#333; }
		#buttonbar #current a { background-position:0 -150px; border-width:0; }
		#buttonbar #current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }
		#buttonbar a:hover { background-position:0% -150px; }
		#buttonbar a:hover span { background-position:100% -150px; }
		</style>";

	$tblColors = array();
	$tblColors = array_pad ($tblColors, count($adminmenu), ""); 
	
	if($currentoption>=0) {
		$tblColors[$currentoption] = 'current';
	}
	echo "<div id='buttontop' style='border-right: 1px solid black;border-left: 1px solid black;margin-bottom:8px;padding-bottom:0;'>"; 
	echo "<table style='width: 100%; padding:0;' cellspacing='0'><tr>";
	echo "<td style=\"width: 60%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">"; if(isset($modversion['config'])){echo"<a class=\"nobutton\" href=\"../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=".$xoopsModule->getVar('mid')."\">Preferences</a> | ";} echo"<a href=\"../index.php\">Go to module</a>"; if(isset($modversion['hasHelp']) && $modversion['hasHelp']==1){echo"| <a href=\"".$modversion['helpUrl']."\">Help</a>";} echo "</td>";
	echo "<td style=\"width: 40%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\"><b>" . $xoopsModule->name() . "  </b> " . $breadcrumb . "</td>";
	echo "</tr></table>";
	echo "<div id='buttonbar'>";
	echo "<ul>";
	for($i=0; $i<count($adminmenu); ++$i){ //XOOPS_ROOT_PATH."/modules/".$modversion['dirname']."/admin/
		echo "<li id='" . $tblColors[$i] . "'><a href='".XOOPS_URL."/modules/".$modversion['dirname']."/".$adminmenu[$i]['link']."'><span>" . $adminmenu[$i]['title'] . "</span></a></li>\n";
	}
	echo "</ul></div>";
	echo "</div><div style='margin-bottom:2px;'>&nbsp;</div>";
	
}



//######################################################################'" . XOOPS_URL . "/modules/".$modversion['dirname']."/images/left_both.png'
function news_collapsableBar($tablename = '', $iconname = '')
{

    ?>
	<script type="text/javascript"><!--
	function goto_URL(object)
	{
		window.location.href = object.options[object.selectedIndex].value;
	}

	function toggle(id)
	{
		if (document.getElementById) { obj = document.getElementById(id); }
		if (document.all) { obj = document.all[id]; }
		if (document.layers) { obj = document.layers[id]; }
		if (obj) {
			if (obj.style.display == "none") {
				obj.style.display = "";
			} else {
				obj.style.display = "none";
			}
		}
		return false;
	}

	var iconClose = new Image();
	iconClose.src = '../images/close12.gif';
	var iconOpen = new Image();
	iconOpen.src = '../images/open12.gif';

	function toggleIcon ( iconName )
	{
		if ( document.images[iconName].src == window.iconOpen.src ) {
			document.images[iconName].src = window.iconClose.src;
		} else if ( document.images[iconName].src == window.iconClose.src ) {
			document.images[iconName].src = window.iconOpen.src;
		}
		return;
	}

	//-->
	</script>
	<?php
	echo "<h4 style=\"color: #2F5376; margin: 6px 0 0 0; \"><a href='#' onClick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "');\">";
}






//#########################################
//BEGIN STORY FORM
//#########################################
function storyForm($storyID='', $function){



	include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts, $xoopsUser, $xoopsModuleConfig, $nameOfRegionalDB;
    $myts =& MyTextSanitizer::getInstance(); 
	switch ($function)
{
	case "post":
	$formHeader='Post Local News';
	break;
	
	case "editLocal":
	$formHeader='Edit Local News';
	break;
	
	case "postRegional":
	$formHeader='Post '.$nameOfRegionalDB.' Only News'; 
	break;
	
	case "editRegional":
	$formHeader='Edit '.$nameOfRegionalDB.' Only News';
	break;	
}


	if($storyID!=''){//get story info for editing....
			if($function!='editRegional'){//get local news stories
				$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("local_news_stories")." WHERE ID = '$storyID'" ) ;
				if ( $result ) {
					$myrow = $xoopsDB->fetchArray($result);
				}	
			}else{//get southeast only stories
				$link = mysql_connect($xoopsModuleConfig['syndicationDB_Host'], $xoopsModuleConfig['syndicationDB_User'], $xoopsModuleConfig['syndicationDB_Passaword']) or ($error = mysql_error());
				mysql_select_db($xoopsModuleConfig['syndicationDB']) or ($error = "Could not select database");
				$Query = "SELECT * FROM CA_SE_News WHERE ID = '$storyID'";
				$result = mysql_query ($Query, $link) or ($error = "Query failed");
				$myrow = mysql_fetch_array($result, MYSQL_ASSOC);
				mysql_free_result($result);
				mysql_close ($link);
			}
		

	}else{
		//initialize form variables
		$myrow['headline']='';
		$myrow['byline']='';
		$myrow['dateline']='';	
		$myrow['tease'] = ''; 
		$myrow['copyright'] = '';
		$myrow['credit']='';
		$myrow['caption']='';
		$myrow['body']='';
	}
	
//#######################################################	
//JAVASCRIPT FOR SHOWING PREVIEW
//#######################################################		
	echo "<script language= 'JavaScript' type='text/JavaScript'>
<!--
function showPreview(){
moveDiv('preview');
document.getElementById('headlinePreview').innerHTML = document.storyform.headline.value;
document.getElementById('bylinePreview').innerHTML = document.storyform.byline.value + ', ' + document.storyform.copyright.value; 
document.getElementById('teasePreview').innerHTML = document.storyform.dateline.value + ' (".date("Y-m-d").") ' + document.storyform.tease.value; 
	if(document.storyform.copyright.value != ''){
		document.getElementById('copyRight').innerHTML = '&copy; Copyright ' + ' ".date("Y").", ' + document.storyform.copyright.value; 
	}
}
//-->
</script>
<link rel='stylesheet' type='text/css' media='all' href='".XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/news.css'."' />

<div id='preview' style=' POSITION: absolute; 
 left: 50%;
 margin-left: -200px;
 VISIBILITY: hidden; 
 BACKGROUND-COLOR: #E7E7E7; 
 width: 400px; 
 BORDER-LEFT: 1px solid black; 
 BORDER-TOP: 1px solid black; 
 BORDER-BOTTOM: 3px solid black; 
 BORDER-RIGHT: 3px solid black; 
 PADDING-TOP: 5px; 
 PADDING-RIGHT: 10px; 
 PADDING-LEFT: 10px; 
 PADDING-BOTTOM: 10px; 
 z-index:999;text-align:left'>
 
  <P CLASS='headline-block'>
	 <DIV CLASS='headline-large' id='headlinePreview'>&nbsp;</DIV>
	 <div id='bylinePreview'>&nbsp;</div>
  </P>
  <div id='teasePreview' CLASS='article' style='padding-top:15px;'></div>
<div id='copyRight' style='padding-top:15px;' CLASS='article'>&nbsp;</div>
 <DIV id='buttonsPreview' style='margin-top:15px; padding:5px; border:1px #000000 solid; text-align:center; background-color:#999999'><input type='button' class='formButton' name='submitPreview'  id='submitPreview' value='Submit Article' onclick=\"showProgress(); document.getElementById('preview').style.visibility = 'hidden'\" /> &nbsp; &nbsp; <input type='button' class='formButton' name='cancelPreview'  id='cancelPreview' value='Cancel' onclick=\"document.getElementById('preview').style.visibility = 'hidden'\" /></DIV>
 </div> ";	

	
//#######################################################	
//JAVASCRIPT FOR SHOWING PROGRESS BAR AND SUBMITTING FORM
//#######################################################	
	echo"
	<script language='JavaScript' type='text/JavaScript'>
<!--

function moveDiv(ID){

//Determine Window Sizes
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }


  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }



var newY = (myHeight/2) + scrOfY;
document.getElementById(ID).style.visibility = 'visible';
document.getElementById(ID).style.top = eval(\"'\" + newY +  \"px'\");
}

//#########################################################################################


function showProgress(){
if(xoopsFormValidate_storyform() == true){

	moveDiv('progress');
	document.storyform.post.disabled = true;
	document.storyform.preview.disabled = true;
	document.storyform.submit();


}

}
//-->
</script>\n
<div id='progress' style=' POSITION: absolute; 
 left: 50%;
 margin-left: -100px;
 VISIBILITY: hidden; 
 BACKGROUND-COLOR: #E7E7E7; 
 width: 200px; 
 BORDER-LEFT: 1px solid black; 
 BORDER-TOP: 1px solid black; 
 BORDER-BOTTOM: 3px solid black; 
 BORDER-RIGHT: 3px solid black; 
 PADDING: 10px; 
 z-index:999;text-align:center'><img src=\"../images/uploading_files.gif\"></div>

"; 


if((isset($myrow['image']) && $myrow['image'] != '') || (isset($myrow['soundfile']) && $myrow['soundfile'] != '')){//get story info for editing.... 
	if(!$myrow['soundfile']){
		$soundFile='No Sound File';
	}else{
	    if($function!='editRegional'){//get local news audio clip 
			$soundFile = $myrow['soundfile'];
			$soundMedia="../media/audio/".$myrow['soundfile'];
		}else{//regional shite  
			//$soundFile = substr($myrow['soundfile'], strrchr ($myrow['soundfile'], "/"),strlen($myrow['soundfile']));;
			$soundFile = str_replace ("/", "", strrchr ($myrow['soundfile'], "/"));
			$soundMedia=$myrow['soundfile'];
		}
	}
	
	
	if($myrow['image'] == ""){
		$imageFile='No Image';
		$imageMedia="";
	}else{
	    if($function!='editRegional'){//get local news audio clip 
			$imageFile = $myrow['image'];
			$imageMedia="<img src='../media/pictures/".substr_replace($myrow['image'], '-TN.jpg', -4)."'>";
		}else{
			$imageFile = str_replace ("/", "", strrchr ($myrow['image'], "/"));
			$imageMedia="<img src='".substr_replace($myrow['image'], '-TN.jpg', -4)."'>";
		}
	}




//PREVIEW MEIDA USED IN STORY IF IT IS AVAILABLE FOR EDIT NEWS
  echo "<div style='width:550px; margin-bottom:5px;padding:3px;border:1px solid #000000;background-color:#cccccc; color:#000000;font-weight:600;font-size:12px;'>Media Files: ".$myrow['headline']."
  <div style='background-color:#ffffff; margin-top:4px;'>
  <table border='0'  cellpadding='0' cellspacing='0' >
	  <tr><td style='padding-bottom:8px;' width='310'><span style='text-decoration:underline; font-size:10px;'>Audio File:</span> <span style='font-size:11px;font-weight:normal; text-decoration:none;'>".$soundFile."<span></td><td style='padding-bottom:8px;'><span style='text-decoration:underline; font-size:10px;'>Image File:</span> <span style='font-size:11px;font-weight:normal; text-decoration:none;'>".$imageFile."</span></td></tr>
	  <tr ><td align='left' valign='top' >
	  <!--BEGIN MP3 PLAYER-->
		<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='300' height='75' id='mp3Player' align='middle'>
		<param name='allowScriptAccess' value='sameDomain' />
		<param name='movie' value='../media/mp3Player.swf' />
		<param name='quality' value='high' />
		<param name='bgcolor' value='#ffffff' />";
		echo"<PARAM NAME=FlashVars VALUE='file=$soundMedia'>
		<embed src='../media/mp3Player.swf' FlashVars='file=$soundMedia' quality='high' bgcolor='#ffffff' width='300' height='75' name='mp3Player' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />
		</object>
	  <!--END MP3 PLAYER-->
	  </td><td style='border:0px solid #000000'>$imageMedia</td></tr>
</table>
  </div>
  </div>";
}

	
//quoteString($myts->stripSlashesGPC($myrow['headline']))

	echo"<span style='font-size:10px;'>* Indicates required fields</span>";
	$sform = new XoopsThemeForm($formHeader, "storyform", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/formaction.php');
	$sform->setExtra('enctype="multipart/form-data"');
	//-------------
	$sform->addElement(new XoopsFormText('Headline', 'headline', 50, 255, $myts->displayTarea($myrow['headline'])), true);
	
	//-------------
	$sform->addElement(new XoopsFormText("Byline", 'byline', 50, 255, $myrow['byline']), false);
	
	//-------------
	$sform->addElement(new XoopsFormText("Dateline", 'dateline', 50, 255, $myrow['dateline']), true);
	
	//-------------
	$editor=new XoopsFormTextArea("Tease", 'tease', $myts->makeTboxData4Show($myrow['tease']), $rows=5, $cols=50, $id = "");
	$sform->addElement($editor,true);
	
	//-------------
	$sform->addElement(new XoopsFormFile('Sound File(.mp3)', 'soundfile', '150000000'), false);		
	//-------------


if($function != 'postRegional' && $function != 'editRegional'){
	//-------------
	if($xoopsModuleConfig['enableSyndication'] == 1){
		if($storyID!=''){
			$sform->addElement(new XoopsFormRadioYN("Post in $nameOfRegionalDB News Also?", 'syndicate', $myrow['syndicate'], _YES, _NO));
		}else{
			$sform->addElement(new XoopsFormRadioYN("Post in $nameOfRegionalDB News Also?", 'syndicate', 0, _YES, _NO));
		}
	}else{
		$sform->addElement(new XoopsFormHidden('syndicate', 0));		
	}
}else{//put in regional DB only
	$sform->addElement(new XoopsFormHidden('regionalOnly', 1));	
	$sform->addElement(new XoopsFormHidden('syndicate', 1));		
}

	//-------------
	$copyright = new XoopsFormSelect('Copyright Source', 'copyright', $myrow['copyright'], $size=1, $multiple=false);
	$copyright->addOption('','No Copyright Information');
	$copyright->addOption('Raven Radio Foundation Inc.','KCAW: Raven Radio Foundation Inc.');
	$copyright->addOption('Rainbird Community Broadcasting','KRBD: Rainbird Community Broadcasting');
	$copyright->addOption('Wrangell Radio Group','KSTK: Wrangell Radio Group');
	$copyright->addOption('Narrows Broadcasting Corp.','KFSK: Narrows Broadcasting Corp.');
	$copyright->addOption('Capital City Broadcasting Inc.','KTOO: Capital City Broadcasting, Inc.');
	$copyright->addOption('CoastAlaska','CoastAlaska'); 
	$sform->addElement($copyright);
	
	
	
	//-------------
	if($storyID!=''){
		$sform->addElement(new XoopsFormDateTime('Publish Date', 'publish_date', 15, $myrow['publish_date']));
		$sform->addElement(new XoopsFormDateTime('Expiration Date', 'expiration_date', 15,$myrow['expiration_date']));
	}else{
		$sform->addElement(new XoopsFormDateTime('Publish Date', 'publish_date', 15, time()));
		$sform->addElement(new XoopsFormDateTime('Expiration Date', 'expiration_date', 15, (time() + 2592000)));
	}

	
		
	//-------------
	$sform->addElement(new XoopsFormFile('Image File (.jpg or .png only)', 'image', '10000000'));	
	
	//-------------
	$sform->addElement(new XoopsFormText("Image Credit", 'credit', 50, 255, $myts->displayTarea($myrow['credit'])), false);	
	
	//-------------
	$editor=new XoopsFormTextArea("Image Caption", 'caption', $myts->displayTarea($myrow['caption']), $rows=3, $cols=25, $id = "");
	$sform->addElement($editor,false);	
	
	
	//-------------	$form->addElement(new XoopsFormDhtmlTextArea('Program Schedule Announcements', 'announcements', $announcements, 5, 35), $required = false);
	    $fckeditor_root = XOOPS_ROOT_PATH.'/modules/local_news/admin/FCKeditor/';
		include XOOPS_ROOT_PATH.'/modules/local_news/admin/FCKeditor/fckeditor.php';
		ob_start();
		//OLDER VERSION OF EDITOR - DOES NOT WORK WITH FIREFOX 3 AND OTHERS
		$oFCKeditor = new FCKeditor('body') ;
		$oFCKeditor->BasePath = XOOPS_URL."/modules/local_news/admin/FCKeditor/" ;
		$oFCKeditor->Value	= html_entity_decode($myrow['body']);
		$oFCKeditor->Height	= 400 ;
		$oFCKeditor->Width = 600 ;
		$oFCKeditor->ToolbarSet = 'CoastAlaska' ; 
		$oFCKeditor->Create() ;
		/*$basePath = XOOPS_URL."/include/fckeditor/" ;
		$oFCKeditor = new FCKeditor('body') ;
		$oFCKeditor->BasePath	= $basePath ;
		$oFCKeditor->Config['SkinPath'] = $basePath . 'editor/skins/office2003/' ;
		$oFCKeditor->ToolbarSet = 'CoastAlaska';
		$oFCKeditor->Height	= 400 ;
		$oFCKeditor->Value	= $myrow['body'];
		$oFCKeditor->Create() ;*/
		$sform->addElement(new XoopsFormLabel('Body', ob_get_contents())); 
		ob_end_clean(); 
	



	//Submit buttons
	$button_tray = new XoopsFormElementTray('' ,'');
	$preview_btn = new XoopsFormButton('', 'preview', 'Preview Text\' onclick=\'showPreview();', 'button');
	$button_tray->addElement($preview_btn);
	$submit_btn = new XoopsFormButton('', 'post', 'Submit\' onclick=\'showProgress();', 'button');
	$button_tray->addElement($submit_btn);
	$sform->addElement($button_tray);

	//-------------
	if($storyID!=''){
		$sform->addElement(new XoopsFormHidden('action', 'update_newstory'));//update news story	
		$sform->addElement(new XoopsFormHidden('ID', $storyID));		
	}else{
		$sform->addElement(new XoopsFormHidden('action', 'newstory'));//enter new story
	}



	$sform->display();


}

//#########################################
//END STORY FORM
//#########################################

	
//##############################################
//FUNCTION TO VIEW/MANAGE NEWS STORIES
//##############################################

function manageNews($source=""){//get either local or regional stories
    global $xoopsDB, $xoopsConfig, $xoopsModule,$xoopsModuleConfig;
	$recentArray = array();
	$expiredArray = array();
	if($source!='regional'){//GET LOCAL NEWS STORIES
		$result = $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix("local_news_stories")." ORDER BY publish_date DESC, ID desc" ) ;
		if ( $result ) {
		//$dataArray = array();
		while ( $myrow = $xoopsDB->fetchArray($result) ) {
			if($myrow['expiration_date'] <= mktime() && $myrow['expiration_date'] != 0 && $myrow['expiration_date'] != -1){
				$expiredArray[] = $myrow;
			}else{
				$recetnArray[] = $myrow;
			}
		
		}
	}
	}else{//GET REGIONAL NEWS STORIES
		$link = mysql_connect($xoopsModuleConfig['syndicationDB_Host'], $xoopsModuleConfig['syndicationDB_User'], $xoopsModuleConfig['syndicationDB_Passaword']) or ($error = mysql_error());
		mysql_select_db($xoopsModuleConfig['syndicationDB']) or ($error = "Could not select database");
	    $Query = "SELECT * FROM CA_SE_News WHERE storyID LIKE 'REGI%' ORDER BY publish_date DESC, ID desc";
	    $result = mysql_query ($Query, $link) or ($error = "Query failed");
	    if($result){
			while ($myrow = mysql_fetch_array($result, MYSQL_ASSOC)) {
				if($myrow['expiration_date'] <= mktime() && $myrow['expiration_date'] != 0 && $myrow['expiration_date'] != -1){
					$expiredArray[] = $myrow;
				}else{
					$recetnArray[] = $myrow;
				}
	        }
         mysql_free_result($result);
	    }
	   
	    mysql_close ($link);
	}	
	
	
	
	
//#######################################################	
//JAVASCRIPT FOR SHOWING PREVIEW
//#######################################################		

//#######################################################	
//JAVASCRIPT FOR SHOWING PROGRESS BAR AND SUBMITTING FORM
//#######################################################	


echo "<script type='text/javascript' src='js/adminJS.js'></script>";
echo "<link rel='stylesheet' type='text/css' media='all' href='".XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/news.css'."' />

<!--DIV FOR DISPLAYING NEWS PREVIEW-->
<div id='preview' style=' POSITION: absolute; 
 left: 50%;
 margin-left: -200px;
 VISIBILITY: hidden; 
 BACKGROUND-COLOR: #E7E7E7; 
 width: 400px; 
 BORDER-LEFT: 1px solid black; 
 BORDER-TOP: 1px solid black; 
 BORDER-BOTTOM: 3px solid black; 
 BORDER-RIGHT: 3px solid black; 
 PADDING-TOP: 5px; 
 PADDING-RIGHT: 10px; 
 PADDING-LEFT: 10px; 
 PADDING-BOTTOM: 10px; 
 z-index:999;text-align:left'>
 
  <DIV CLASS='headline-block'id='previewDiv'>
  </DIV><br id='spacer' clear='all' />
 <DIV id='buttonsPreview' style='margin-top:15px; padding:5px; border:1px #000000 solid; text-align:center; background-color:#999999'></DIV>
 </div> ";	
	
	
	//CURRENT NEWS STORIES
	news_collapsableBar('recent', 'recentImage');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='recentImage' name='recentImage' src='" . XOOPS_URL . "/modules/local_news/images/close12.gif' alt='' /></a>&nbsp; Current News Stories". ' ('; if(isset($recetnArray)){echo count($recetnArray);} echo ')'."</h4>";
	echo "<div id='recent' style='margin-bottom:15px;'>
	<!--BEGIN COLLAPSABLE DIV-->
	<table width='100%' class='outer' cellspacing='1'><tr><th colspan='6'>&nbsp;</th></tr>
		<tr valign='top' align='left' class='head'><td width='25'>ID</td><td >Title</td><td width='110'>Syndication ID</td><td width='100'>Byline</td><td width='100'>Publish Date</td><td width='150'>Action</td></tr>";
		
		function oddEven($number){
			if($number & 1){
				return "odd";
			}else{
				return "even";
			}
		}
		
		function isImage($image){
		if($image){
			return "true";
			}else{
			return "false";
			}
		}


if(isset($recetnArray) && $source!='regional'){//get local stories
		$x=0;
		foreach($recetnArray as $recent){
			echo "<tr valign='top' align='left' class='".oddEven($x)."'><td >".$recent['ID']."</td><td >".$recent['headline']."</td><td>".$recent['storyID']."</td><td >".$recent['byline']."</td><td>".date("m/d/y",$recent['publish_date'])."</td><td><a href='index.php?op=editLocal&amp;currentID=1&amp;ID=".$recent['ID']."'>Edit</a> - <a href='index.php?op=deleteStory&amp;currentID=1&amp;ID=".$recent['ID']."&amp;title=".$recent['headline']."'>Delete</a> - <a href='javascript:void(0);' onClick=\"showPreview(".$recent['ID'].",'false');\">Preview</a></td></tr>";
		++$x;
		}
}elseif(isset($recetnArray)){//get regional ONLY stories
		$x=0;
		foreach($recetnArray as $recent){
			echo "<tr valign='top' align='left' class='".oddEven($x)."'><td >".$recent['ID']."</td><td >".$recent['headline']."</td><td>".$recent['storyID']."</td><td >".$recent['byline']."</td><td>".date("m/d/y",$recent['publish_date'])."</td><td><a href='index.php?op=editRegional&amp;currentID=3&amp;ID=".$recent['ID']."'>Edit</a> - <a href='index.php?op=deleteStory&amp;regionalOnly=true&amp;currentID=1&amp;ID=".$recent['ID']."&amp;title=".$recent['headline']."'>Delete</a> - <a href='javascript:void(0);' onClick=\"showPreview(".$recent['ID'].",'true');\">Preview</a></td></tr>";
		++$x;
		}
}


	echo"</table><!--END COLLAPSABLE DIV-->
	</div>"; 
	
	//EXPIRED NEWS STORIES
	news_collapsableBar('expired', 'expiredImage');
	echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='expiredImage' name='expiredImage' src='" . XOOPS_URL . "/modules/local_news/images/close12.gif' alt='' /></a>&nbsp; Expired News Stories". ' (' . count($expiredArray) . ')'."</h4>";
	echo "<div id='expired'>
	<!--BEGIN COLLAPSABLE DIV-->
	<table width='100%' class='outer' cellspacing='1'><tr><th colspan='6'>&nbsp;</th></tr>
		<tr valign='top' align='left' class='head'><td width='25'>ID</td><td >Title</td><td width='110'>Syndication ID</td><td width='100'>Byline</td><td width='100'>Publish Date</td><td width='150'>Action</td></tr>";
		if($source!='regional'){//get local stories
				$x=0;
				foreach($expiredArray as $expired){
					echo "<tr valign='top' align='left' class='".oddEven($x)."'><td >".$expired['ID']."</td><td >".$expired['headline']."</td><td>".$expired['storyID']."</td><td >".$expired['byline']."</td><td>".date("m/d/y",$expired['publish_date'])."</td><td><a href='index.php?op=editLocal&amp;currentID=1&amp;ID=".$expired['ID']."'>Edit</a> - <a href='index.php?op=deleteStory&amp;currentID=1&amp;ID=".$expired['ID']."&amp;title=".$expired['headline']."'>Delete</a> - <a href='javascript:void(0);' onClick=\"showPreview(".$expired['ID'].",'false');\">Preview</a></td></tr>";
				++$x;
				}
		}else{//get regional ONLY stories
				$x=0;
				foreach($expiredArray as $expired){
					echo "<tr valign='top' align='left' class='".oddEven($x)."'><td >".$expired['ID']."</td><td >".$expired['headline']."</td><td>".$expired['storyID']."</td><td >".$expired['byline']."</td><td>".date("m/d/y",$expired['publish_date'])."</td><td><a href='index.php?op=editRegional&amp;currentID=3&amp;ID=".$expired['ID']."'>Edit</a> - <a href='index.php?op=deleteStory&amp;regionalOnly=true&amp;currentID=1&amp;ID=".$expired['ID']."&amp;title=".$expired['headline']."'>Delete</a> - <a href='javascript:void(0);' onClick=\"showPreview(".$expired['ID'].",'true');\">Preview</a></td></tr>";
				++$x;
				}
		}		
		
		echo"</table><!--END COLLAPSABLE DIV-->
	</div>";
	
}


//##############################################
//FUNCTION TO DELETE NEWS STORIES
//##############################################
function deleteStory($regionalOnly){
    global $xoopsDB, $xoopsConfig, $xoopsModule;
	$myts =& MyTextSanitizer::getInstance();
	if($_GET['title']){
		xoops_confirm(array('action'=>'deleteStory','regionalOnly'=>$regionalOnly, 'ID'=>$_GET['ID'],'title'=>$_GET['title']), 'formaction.php', "Are you sure you want to delete this story: ".$myts->htmlSpecialChars(stripslashes($_GET['title']))."?  All associated media files will be deleted as well!");
	}else{
		xoops_confirm(array('action'=>'deleteStory','regionalOnly'=>$regionalOnly, 'ID'=>$_GET['ID']), 'formaction.php', "Are you sure you want to delete this story?  All associated media files will be deleted as well!");
	}

}




?>
